<%@ page import="user.User" %>
<%@ page import="com.example.demo_text.UserDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
  String idStr = request.getParameter("id");
  int id = 0;
  if (idStr != null && !idStr.isEmpty()) {
    try {
      id = Integer.parseInt(idStr);
    } catch (NumberFormatException ignored) {}
  }

  User student = UserDAO.getUserById(id);
  if (student == null) {
    response.sendRedirect("admitmanageStudent.jsp");
    return;
  }
%>

<html>
<head>
  <title>编辑学生信息</title>
  <style>
    /* 引用 home.jsp 的统一风格 */
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
      background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 40px 20px;
      color: #333;
    }

    .card {
      background: white;
      width: 100%;
      max-width: 600px;
      padding: 30px 25px;
      border-radius: 16px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
      transition: all 0.3s ease;
      text-align: center;
    }

    .card:hover {
      transform: translateY(-5px);
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    }

    h2 {
      text-align: center;
      margin-bottom: 24px;
      font-weight: 600;
      color: #374151;
    }

    label {
      display: block;
      text-align: left;
      margin-top: 15px;
      margin-bottom: 5px;
      font-weight: 500;
    }

    input[type="text"],
    input[type="email"],
    input[type="number"] {
      width: 100%;
      padding: 10px 15px;
      margin-bottom: 20px;
      border: 1px solid #ccc;
      border-radius: 6px;
    }

    button {
      width: 100%;
      padding: 12px;
      background-color: #d1ecf1;
      color: #15576b;
      border: none;
      border-radius: 8px;
      font-size: 16px;
      cursor: pointer;
      transition: background 0.3s, color 0.3s;
    }

    button:hover {
      background-color: #aee2eb;
      color: #0f3d4d;
    }

    a.back-link {
      display: block;
      text-align: center;
      margin-top: 20px;
      color: #3498db;
      text-decoration: underline;
      font-size: 14px;
    }

    a.back-link:hover {
      color: #2980b9;
    }
  </style>
</head>
<body>

<div class="card">
  <h2>🎓 编辑 <%= student.getUsername() %> 的信息</h2>
  <form action="AdmitUpdateStudentServlet" method="post">
    <input type="hidden" name="id" value="<%= student.getId() %>" />

    <label for="username">用户名：</label>
    <input type="text" id="username" name="username" value="<%= student.getUsername() %>" required />

    <label for="email">邮箱：</label>
    <input type="email" id="email" name="email" value="<%= student.getEmail() %>" required />

    <label for="age">年龄：</label>
    <input type="number" id="age" name="age" value="<%= student.getAge() %>" min="0" max="150" required />

    <button type="submit">保存更改</button>
  </form>
  <a href="admitmanageStudent.jsp" class="back-link">返回学生列表</a>
</div>

</body>
</html>
